package com.imy.rootserver.gesture;

import android.util.Log;

import com.imy.rootserver.handler.HandlerDispatch;
import com.imy.rootserver.socket.TcpServer;

import static com.imy.rootserver.constant.Constant.GESTURE;
import static com.imy.rootserver.constant.Constant.SWIPE;
import static com.imy.rootserver.constant.Constant.TAKE_SCREEN;

/**
 * Created by Administrator on 2019/4/6/006.
 */

public class TaskHandler implements TaskInterface {

  private String TAG = "TaskHandler";

  private HandlerDispatch mHandlerDispatch;

  public TaskHandler(TcpServer server) {
    mHandlerDispatch = new HandlerDispatch(server);

  }

  @Override
  public synchronized void handTask(String receive) {
    //解析事件
    if (receive == null || receive.equals("")) {
      return;
    }
    String[] s = receive.split(" ");
    String action = s[0];

    if (action.equals(GESTURE)) {
      String event = s[1];
      float x = Float.parseFloat(s[2]);
      float y = Float.parseFloat(s[3]);
      int id = Integer.parseInt(s[4]);
      mHandlerDispatch.dispatchGesture(event, x, y, id);
    } else if (action.equals(TAKE_SCREEN)) {
      String flag = s[1];
      Log.i(TAG, "接收截屏事件 标记:" + flag);
      mHandlerDispatch.dispatchScreen(flag);
    } else if (action.equals(SWIPE)) {

      //mHandlerDispatch.dispatchSwipe();
    }
  }

}
